package com.szsfm.vehiclemanagement.terminal;


import com.szsfm.vehiclemanagement.exception.TerminalInitializeException;
import com.szsfm.vehiclemanagement.interfaces.ICardOperate;
import com.szsfm.vehiclemanagement.interfaces.IPrinter;

/**
 * Created by zhoubigbo on 2017/11/21.
 */
public class Terminal {

    public IPrinter printer;
    public ICardOperate cardOperate;

    private Terminal() {}

    protected Terminal(Builder builder) {
        if (builder.printer == null) {
            throw new TerminalInitializeException("打印机不能为空");
        }
        if (builder.cardOperate == null) {
            throw new TerminalInitializeException("卡操作模块不能为空");
        }

        this.printer = builder.printer;
        this.cardOperate = builder.cardOperate;
    }

    public static class Builder {
        IPrinter printer;
        ICardOperate cardOperate;

        public Builder addPrinter(IPrinter printer) {
            this.printer = printer;
            return this;
        }

        public Builder addCardOperate(ICardOperate cardOperate) {
            this.cardOperate = cardOperate;
            return this;
        }

        public Terminal build() {
            return new Terminal(this);
        }

    }

}
